package com.example.demo.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Util {
    //获取项目工作路径
    public static final String WORKING_PATH = System.getProperty("user.dir");

    public static final int LOWEST_RANK = 1000;

    //cmd执行python命令
    public static void exec(String path,String arg){
        Process proc;
        try {
            String[] args = new String[] {"python ", Util.WORKING_PATH+path,arg};
            proc = Runtime.getRuntime().exec(args);// 执行py文件
            //用输入输出流来截取结果
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            in.close();
            proc.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public static void execs(String path,String analysis_file,String background_pic,String color,String  save_path,String save_file_name,String save_pic_name){
        Process proc;
        try {
            String[] args = new String[] {"python ", Util.WORKING_PATH+path,analysis_file,background_pic, color,save_path,save_file_name,save_pic_name};
            proc = Runtime.getRuntime().exec(args);// 执行py文件
            //用输入输出流来截取结果
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            in.close();
            proc.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
